package com.liang.three;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import utils.RabbitmqUtil;

import java.io.IOException;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * User: XIAOLIANG
 * Date: 2021/6/17
 * Time: 19:00
 * Description: 消息在手动应答是不丢失的
 */
public class Task2 {

    public static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitmqUtil.getChannel();

        //声明 一个队列
         channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, null);


         //从控制台中 获取信息

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){

            String next = scanner.next();

            //将消息发送出去
//            // MessageProperties.PERSISTENT_TEXT_PLAIN 消息的持久化 会将消息保存在磁盘上
            channel.basicPublish("",TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,next.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者 发送消息 ,"+next);
        }

    }

}